package TreeHole.mod;

import TreeHole.patches.TreeHolePatch;
import basemod.BaseMod;
import basemod.interfaces.EditStringsSubscriber;
import basemod.interfaces.ISubscriber;
import basemod.interfaces.PostInitializeSubscriber;
import com.badlogic.gdx.Gdx;
import com.evacipated.cardcrawl.modthespire.lib.SpireInitializer;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.localization.EventStrings;
import com.megacrit.cardcrawl.localization.UIStrings;

import java.nio.charset.StandardCharsets;

@SpireInitializer
public class TreeHoleMod implements ISubscriber, EditStringsSubscriber, PostInitializeSubscriber {
    public TreeHoleMod() {
        BaseMod.subscribe(this);
        ModConfig.initModSettings();
    }

    public static void initialize(){
        new TreeHoleMod();
    }

    public static void registerTreeHole(String dungeonID,TreeHoleBase base){
        TreeHoleHelper.addTreeHole(dungeonID,base);
    }

    @Override
    public void receivePostInitialize() {
        ModConfig.initModConfigMenu();
    }

    @Override
    public void receiveEditStrings() {
        String ui = "TreeHoleResources/localization/";
        String event = "TreeHoleResources/localization/";
        if(Settings.language== Settings.GameLanguage.ZHS||Settings.language== Settings.GameLanguage.ZHT){
            ui += "zh/ui-zh.json";
            event += "zh/event-zh.json";
        }
        else{
            ui += "en/ui-en.json";
            event += "en/event-en.json";
        }
        String eventStrings = Gdx.files.internal(event).readString(String.valueOf(StandardCharsets.UTF_8));
        BaseMod.loadCustomStrings(EventStrings.class, eventStrings);
        String uiStrings = Gdx.files.internal(ui).readString(String.valueOf(StandardCharsets.UTF_8));
        BaseMod.loadCustomStrings(UIStrings.class,uiStrings);
    }
}
